package com.jinmdz.fmis.mapper.mapper.provider;

import com.jinmdz.fmis.mapper.entity.ChargeSettleEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * 费用结算表Provider
 *
 * @author generator
 * @date 2020-05-12 14:24
 */
public class ChargeSettleProvider {

    /**
     * 增加ChargeSettle
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-05-12 14:24
     */
    public String insertChargeSettle(@Param("entity") ChargeSettleEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" charge_settle ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" business_code ", " #{entity.businessCode,jdbcType=VARCHAR} ");
                VALUES(" settle_batch_no ", " #{entity.settleBatchNo,jdbcType=VARCHAR} ");
                VALUES(" receipt_charge ", " #{entity.receiptCharge,jdbcType=DECIMAL} ");
                VALUES(" discount_charge ", " #{entity.discountCharge,jdbcType=DECIMAL} ");
                VALUES(" benefit_charge ", " #{entity.benefitCharge,jdbcType=DECIMAL} ");
                VALUES(" settle_charge ", " #{entity.settleCharge,jdbcType=DECIMAL} ");
                VALUES(" settle_time ", " #{entity.settleTime,jdbcType=TIMESTAMP} ");
                VALUES(" settle_type_code ", " #{entity.settleTypeCode,jdbcType=SMALLINT} ");
                VALUES(" receipt_no ", " #{entity.receiptNo,jdbcType=VARCHAR} ");

                if (entity.getAsRefund() != null) {
                    VALUES(" as_refund ", " #{entity.asRefund,jdbcType=TINYINT} ");
                }


                if (entity.getAsVerify() != null) {
                    VALUES(" as_verify ", " #{entity.asVerify,jdbcType=TINYINT} ");
                }

                VALUES(" verify_id ", " #{entity.verifyId,jdbcType=INTEGER} ");

                if (entity.getAsInvoice() != null) {
                    VALUES(" as_invoice ", " #{entity.asInvoice,jdbcType=TINYINT} ");
                }

                VALUES(" invoice_id ", " #{entity.invoiceId,jdbcType=INTEGER} ");
                VALUES(" settle_user_id ", " #{entity.settleUserId,jdbcType=INTEGER} ");
                VALUES(" random_code ", " #{entity.randomCode,jdbcType=VARCHAR} ");
                VALUES(" remark ", " #{entity.remark} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改ChargeSettle
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-05-12 14:24
     */
    public String updateChargeSettle(@Param("entity") ChargeSettleEntity entity) {
        return new SQL() {
            {
                UPDATE(" charge_settle ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                SET(" settle_batch_no = #{entity.settleBatchNo,jdbcType=VARCHAR} ");
                SET(" receipt_charge = #{entity.receiptCharge,jdbcType=DECIMAL} ");
                SET(" discount_charge = #{entity.discountCharge,jdbcType=DECIMAL} ");
                SET(" benefit_charge = #{entity.benefitCharge,jdbcType=DECIMAL} ");
                SET(" settle_charge = #{entity.settleCharge,jdbcType=DECIMAL} ");
                SET(" settle_time = #{entity.settleTime,jdbcType=TIMESTAMP} ");
                SET(" settle_type_code = #{entity.settleTypeCode,jdbcType=SMALLINT} ");
                SET(" receipt_no = #{entity.receiptNo,jdbcType=VARCHAR} ");

                if (entity.getAsRefund() != null) {
                    SET(" as_refund = #{entity.asRefund,jdbcType=TINYINT} ");
                }


                if (entity.getAsVerify() != null) {
                    SET(" as_verify = #{entity.asVerify,jdbcType=TINYINT} ");
                }

                SET(" verify_id = #{entity.verifyId,jdbcType=INTEGER} ");

                if (entity.getAsInvoice() != null) {
                    SET(" as_invoice = #{entity.asInvoice,jdbcType=TINYINT} ");
                }

                SET(" invoice_id = #{entity.invoiceId,jdbcType=INTEGER} ");
                SET(" settle_user_id = #{entity.settleUserId,jdbcType=INTEGER} ");
                SET(" random_code = #{entity.randomCode,jdbcType=VARCHAR} ");
                SET(" remark = #{entity.remark} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询ChargeSettle列表
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-05-12 14:24
     */
    public String listChargeSettle(@Param("entity") ChargeSettleEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,business_code,settle_batch_no,receipt_charge,discount_charge,benefit_charge,settle_charge,settle_time,settle_type_code,receipt_no,as_refund,as_verify,verify_id,as_invoice,invoice_id,settle_user_id,random_code,remark,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" charge_settle ");

                if (entity.getBusinessCode() != null) {
                    WHERE(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                }

                if (entity.getSettleBatchNo() != null) {
                    WHERE(" settle_batch_no = #{entity.settleBatchNo,jdbcType=VARCHAR} ");
                }

                if (entity.getReceiptCharge() != null) {
                    WHERE(" receipt_charge = #{entity.receiptCharge,jdbcType=DECIMAL} ");
                }

                if (entity.getDiscountCharge() != null) {
                    WHERE(" discount_charge = #{entity.discountCharge,jdbcType=DECIMAL} ");
                }

                if (entity.getBenefitCharge() != null) {
                    WHERE(" benefit_charge = #{entity.benefitCharge,jdbcType=DECIMAL} ");
                }

                if (entity.getSettleCharge() != null) {
                    WHERE(" settle_charge = #{entity.settleCharge,jdbcType=DECIMAL} ");
                }

                if (entity.getSettleTime() != null) {
                    WHERE(" settle_time = #{entity.settleTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getSettleTypeCode() != null) {
                    WHERE(" settle_type_code = #{entity.settleTypeCode,jdbcType=SMALLINT} ");
                }

                if (entity.getReceiptNo() != null) {
                    WHERE(" receipt_no = #{entity.receiptNo,jdbcType=VARCHAR} ");
                }

                if (entity.getAsRefund() != null) {
                    WHERE(" as_refund = #{entity.asRefund,jdbcType=TINYINT} ");
                }

                if (entity.getAsVerify() != null) {
                    WHERE(" as_verify = #{entity.asVerify,jdbcType=TINYINT} ");
                }

                if (entity.getVerifyId() != null) {
                    WHERE(" verify_id = #{entity.verifyId,jdbcType=INTEGER} ");
                }

                if (entity.getAsInvoice() != null) {
                    WHERE(" as_invoice = #{entity.asInvoice,jdbcType=TINYINT} ");
                }

                if (entity.getInvoiceId() != null) {
                    WHERE(" invoice_id = #{entity.invoiceId,jdbcType=INTEGER} ");
                }

                if (entity.getSettleUserId() != null) {
                    WHERE(" settle_user_id = #{entity.settleUserId,jdbcType=INTEGER} ");
                }

                if (entity.getRandomCode() != null) {
                    WHERE(" random_code = #{entity.randomCode,jdbcType=VARCHAR} ");
                }

                if (entity.getRemark() != null) {
                    WHERE(" remark = #{entity.remark} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}